define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user_miner/index' + location.search,
                    add_url: 'user_miner/add',
                    edit_url: 'user_miner/edit',
                    del_url: 'user_miner/del',
                    multi_url: 'user_miner/multi',
                    table: 'user_miner',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_no', title: __('Order_no')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'user.mobile', title: __('用户电话')},
                        {field: 'user.nickname', title: __('用户昵称')},
                        {field: 'name', title: __('Name')},
                        {field: 'image', title: __('Image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'number', title: __('Number'), operate:'BETWEEN'},
                        {field: 'balance_number', title: __('Balance_number'), operate:'BETWEEN'},
                        {field: 'pledge', title: __('Pledge'), operate:'BETWEEN'},
                        // {field: 'max_pledge', title: __('Max_pledge'), operate:'BETWEEN'},
                        // {field: 'gift_pledge', title: __('Gift_pledge'), operate:'BETWEEN'},
                        {field: 'gas', title: __('Gas'), operate:'BETWEEN'},
                        {field: 'max_gas', title: __('Max_gas'), operate:'BETWEEN'},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'day', title: __('Day')},
                        {field: 'day_balance', title: __('Day_balance')},
                        // {field: 'begin_day', title: __('Begin_day')},
                        {field: 'duration', title: __('Duration')},
                        {field: 'direct_push', title: __('Direct_push'), operate:'BETWEEN'},
                        {field: 'second_push', title: __('Second_push'), operate:'BETWEEN'},
                        {field: 'service_rate', title: __('Service_rate'), operate:'BETWEEN'},
                        {field: 'lock_rate', title: __('Lock_rate'), operate:'BETWEEN'},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'pledge_status', title: __('Pledge_status'), searchList: {"0":__('Pledge_status 0'),"1":__('Pledge_status 1')}, formatter: Table.api.formatter.status},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Type 3')}, formatter: Table.api.formatter.status},
                        {field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});